﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NeoModulusBusinessRulesDLLBuilder.UserControls;

namespace NeoModulusBusinessRulesDLLBuilder.Dialogs
{
    public partial class AddNewObjectWizard : Form
    {
        public usrObjectTree ObjectTree { get; set; }
        public string NewObjectName { get; set; }
        public AddNewObjectWizard()
        {
            InitializeComponent();
        }

        private void txtObjectToAdd_TextChanged(object sender, EventArgs e)
        {
            if(ObjectTree != null)
            {
                if(!ObjectTree.DoesNameExist(((TextBox) sender).Text))
                {
                    lblInfo.Text = @"Object Name Available";
                    lblInfo.ForeColor = Color.Green;
                }
                else
                {
                    lblInfo.Text = @"Object Name In Use";
                    lblInfo.ForeColor = Color.Red; 
                }
            }
        }

        private void btnAddObject_Click(object sender, EventArgs e)
        {
            if (lblInfo.ForeColor == Color.Green)
            {
                NewObjectName = txtObjectToAdd.Text;
                this.DialogResult = DialogResult.Yes;
                this.Close();
            }
            else
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();  
            }
            
        }

     
    }
}
